package com.myjpa.generate;

import lombok.Getter;
import lombok.Setter;

/**
 * @author: yaoll
 * @date: 2020-09-07
 * @verison: 1.0
 */
@Getter
@Setter
public class ModelGenerator {

	private StringBuilder buff;

	public void generate(GenerateContext ctx) {

		buff = new StringBuilder();
		buff.append("package " + ctx.getPkg() + ".model;\n");
		buff.append("\n");
		buff.append("import lombok.Getter;").append("\n");
		buff.append("import lombok.Setter;").append("\n");
		buff.append("import java.util.Date;").append("\n");
		buff.append("\n");
		buff.append("@Setter").append("\n");
		buff.append("@Getter").append("\n");
		buff.append("public class " + ctx.getModelClass() + " {").append("\n");
		buff.append("").append("\n");

		GenerateContext.PrimaryKey primaryKey = ctx.getPrimaryKey();
		String name = primaryKey.getName();
		String type = primaryKey.getType();

		buff.append("\t").append("private " + type + " " + name + ";").append("\n");
		for (Attribute att : ctx.getAtts()) {
			buff.append("\t").append("private ").append(att.getType().getSimpleName()).append(" ").append(att.getName()).append(";").append("\n");
		}
		buff.append("\n");

		buff.append("}").append("\n");
	}



}
